package com.cdtu.backend.utils;

import lombok.extern.slf4j.Slf4j;

import java.util.Scanner;
import java.util.concurrent.TimeUnit;

/**
 * @author Mika
 * @date 2023/08/18 21:44
 * CommonUtils 普通工具类
 **/
@Slf4j
public class CommonUtil {
    public static final String GAME_DIRECTORY = "Genshin Impact Game";
    // 打印 banner
    public static void banner() {
        System.out.println("\n" +
                "\n" +
                "////////////////////////////////////////////////////////////////////\n" +
                "//                          _ooOoo_                               //\n" +
                "//                         o8888888o                              //\n" +
                "//                         88\" . \"88                              //\n" +
                "//                         (| ^_^ |)                              //\n" +
                "//                         O\\  =  /O                              //\n" +
                "//                      ____/`---'\\____                           //\n" +
                "//                    .'  \\\\|     |//  `.                         //\n" +
                "//                   /  \\\\|||  :  |||//  \\                        //\n" +
                "//                  /  _||||| -:- |||||-  \\                       //\n" +
                "//                  |   | \\\\\\  -  /// |   |                       //\n" +
                "//                  | \\_|  ''\\---/''  |   |                       //\n" +
                "//                  \\  .-\\__  `-`  ___/-. /                       //\n" +
                "//                ___`. .'  /--.--\\  `. . ___                     //\n" +
                "//              .\"\" '<  `.___\\_<|>_/___.'  >'\"\".                  //\n" +
                "//            | | :  `- \\`.;`\\ _ /`;.`/ - ` : | |                 //\n" +
                "//            \\  \\ `-.   \\_ __\\ /__ _/   .-` /  /                 //\n" +
                "//      ========`-.____`-.___\\_____/___.-`____.-'========         //\n" +
                "//                           `=---='                              //\n" +
                "//      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^        //\n" +
                "//            佛祖保佑       永不宕机     永无BUG                    //\n" +
                "////////////////////////////////////////////////////////////////////" +
                "\n");
    }
    public static void chineseBanner() {
        System.out.println("\n" +
                "                   #       #                              #                  #                        \n" +
                "  ############      #      #                               #                 #                        \n" +
                "  #    #            #      #                          ############   #####   #                        \n" +
                "  #    #         ###### ########                      #         #            #   #                    \n" +
                "  #   #              #  #  #  #                       #         #         ########      #             \n" +
                "  # ##########      #   #  #  #                       #         #   #######  #   #      #             \n" +
                "  # #       #      ###  #  #  #                       ###########      #     #   #      #             \n" +
                "  # #########     # # # #######                       #                #     #   #      #             \n" +
                "  # #       #    #  #   #  #  #                       #         #     #      #   #      #             \n" +
                "  # #########       #   #  #  #                       ############    #  #   #   #      #             \n" +
                "  #     #           #   #  #  #                       ##        #    #    # #    #      #             \n" +
                "  #  #  #  #        #   #######     ##               # #        #   ####### #    #      #             \n" +
                " #   #  #   #       #      #        ##               # #        #    #     #     #      #             \n" +
                " #  #   #    #      #      #         #              #  #        #          #     #                    \n" +
                "#  #  # #    #      #      #        #              #   ##########         #   # #       #             \n" +
                "       #            #      #                           #        #        #     #                      \n" +
              "\n");
    }
    public static void waitSomeTime() {
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }

    // 输入游戏存放路径
    public static String typePath() {
        /*
         * TODO:
         *    1.具体的游戏安装位置需要持久化,保存在配置文件中（X）
         *    2.校验用户输入路径是否合法（✔）
         */
        // 提示：找不到游戏位置，请输入你游戏安装位置
        log.info("请在下方，手动输入你游戏安装位置");
        log.info("提示：此文件夹下你能找到子文件夹 Genshin Impact Game，格式如下");
        log.info("盘符:\\安装路径\\原神文件夹 ===>  E:\\Game\\Application\\Genshin Impact_yuanshen");
        Scanner scanner = new Scanner(System.in);
        String path = "";
        while (true) {
            path = scanner.nextLine();
            if (FileUtil.containChildDirectory(path, GAME_DIRECTORY)) {
                break;
            }
            log.warn("您输入的路径似乎有误，请重新输入");
            log.warn("输入的路径下必须包含子文件夹 Genshin Impact Game\n");
        }
        return path;
    }
}
